package com.front.web.redisTest;

import com.bootdo.BootdoApplication;
import com.bootdo.bj.domain.Context;
import com.bootdo.common.utils.R;
import com.bootdo.redis.RedisUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/f/RedisTest/")
public class RedisTest {


    /**
     * 使用哨兵功能
     */
    @Autowired
    RedisUtil redisUtil;



    /**
     * http://127.0.0.1/f/RedisTest/?key=1&value=2
     * @param request
     * @param response
     * @return
     */
    @RequestMapping
    @ResponseBody
    public R getKey(
            @RequestParam("key") String key,
            @RequestParam("value") String value,
            HttpServletRequest request
            , HttpServletResponse response){

        Context context = new Context();
        context.setUserName(value);
        redisUtil.set(key, context);
        return R.ok(redisUtil.get(key).toString());
    }



}
